/*
 * Created by SharpDevelop.
 * User: michaelo
 * Date: 28/03/2006
 * Time: 08:24
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Diagnostics;

namespace Orz.LogManager
{
	/// <summary>
	/// Description of Log.
	/// </summary>
	public class Log
	{
		public Log()
		{
		}
		
		public static void Debug(string sText_p)
		{
			LogText(sText_p, "DEBUG");
		}
		
		
		public static void Info(string sText_p)
		{
			LogText(sText_p, "INFO ");
		}
		
		
		public static void Warning(string sText_p)
		{
			LogText(sText_p, "WARN ");
		}
		
		
		public static void Error(string sText_p)
		{
			LogText(sText_p, "ERROR");
		}
		
		
		public static void Error(string sText_p, Exception exception_p)
		{
			string sExceptionText = GetExceptionText(exception_p);
			
			while (null != exception_p.InnerException)
			{
				exception_p = exception_p.InnerException;
				sExceptionText += "\n Caused by: \n" + GetExceptionText(exception_p);
			}
			
			LogText(sText_p + "\n" + sExceptionText, "ERROR");
		}
		
		
		
		
		
		
		private static void LogText(string sText_p, string sCategory_p)
		{			
			string sDate = DateTime.Now.ToShortTimeString();
			System.Diagnostics.Debug.WriteLine("[" + sCategory_p + "] " + sDate + ": " + sText_p);
			System.Diagnostics.Debug.Flush();
		}
		
		
		private static string GetExceptionText(Exception e)
		{
			return e.Message + "\n" + e.StackTrace;
		}
	}
}
